﻿using Android.Graphics.Drawables;
using Android.Graphics.Drawables.Shapes;
using Games.Common;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(CircleLabel), typeof(Games.Droid.ControlRenders.CircleLabelRender))]
namespace Games.Droid.ControlRenders
{
    class CircleLabelRender : LabelRenderer
    {
        public CircleLabelRender(Android.Content.Context context) : base(context)
        {

        }
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);
            var stack = e.NewElement as CircleLabel;
            if(stack == null)
            {
                return;
            }
            var shape = new ShapeDrawable(new OvalShape());
            shape.Paint.Color = stack.BackColor.ToAndroid();
            this.Control.SetBackground(shape);
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if(e.PropertyName == CircleLabel.BackColorProperty.PropertyName)
            {
                var lbl = Element as CircleLabel;
                if(lbl == null)
                {
                    return;
                }
                var shape = new ShapeDrawable(new OvalShape());
                shape.Paint.Color = lbl.BackColor.ToAndroid();
                this.Control.SetBackground(shape);
            }
        }
    }
}